<template>
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <notifications group="auth" />
                <div class="user-login text-center">
                    <h2>系统注册</h2>
                    <div class="form-group">
                        <input class="form-control" v-model="param.name" type="text" placeholder="用户名"/>
                    </div>
                    <div class="form-group">
                        <input class="form-control" v-model="param.email" type="text" placeholder="邮箱"/>
                    </div>
                    <div class="form-group">
                        <input class="form-control" v-model="param.password" type="password" placeholder="密码"/>
                    </div>
                    <div class="form-group">
                        <input class="form-control" v-model="param.checkPassword" type="password" placeholder="确认密码"/>
                    </div>
                    <div class="form-group">
                        <button type="button" @click="register" class="form-control btn btn-sm btn-primary">注册</button>
                    </div>
                    <div class="form-group text-right">
                    <router-link to="/login">已经注册</router-link>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
              param: {
                  name: '',
                  email: '',
                  password: '',
                  checkPassword: '',
              }
            }
        },
        mounted() {
            console.log(this.ajax());
        },
        methods: {
            register: function (event){
                var _this = this;
                if(_this.param.password !== _this.param.checkPassword){
                    _this.$notify({
                        group: 'auth',
                        type: 'error',
                        text: '两次输入的密码不一致'
                    });
                    return false;
                }
                axios.post('/api/register', _this.param)
                    .then(function (res) {
                         if(res.data.code === 200){
                             _this.$notify({
                                 group: 'auth',
                                 type: 'success',
                                 text: res.data.msg,
                             });
                         }
                    })
                    .catch(function (error) {
                        _this.$notify({
                            group: 'auth',
                            type: 'error',
                            title: 500,
                            text: '请求服务器发生错误',
                        });
                    });
            },
        },
    }
</script>
